/*
 * 版权所有 (c) 2022-2099 TBIT。保留所有权利。
 */

/*
 * 版权所有 (c) 2022-2099 TBIT。保留所有权利。
 */

package com.tbit.main.sms.enums.template;

import cn.hutool.core.util.ArrayUtil;
import com.alibaba.fastjson.JSONObject;
import com.tbit.main.constant.AccountSmsModelConstant;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author <a href="mailto:li.yao@tbit.com.cn">yao</a>
 * @version 4.1.0
 * @since 2024/7/15 15:51
 */
@Getter
@AllArgsConstructor
public enum ApiStoreSmsTemplateEnum {

    ALARM(SmsCodeTemplateEnum.AlARM.getCode(), AccountSmsModelConstant.SMS_ZC, getAlarmTemplate()),
    ORDER_NO_PAY(SmsCodeTemplateEnum.ORDER_NO_PAY.getCode(), AccountSmsModelConstant.SMS_WZFLJ, getOrderNoPayTemplate()),
    RIDE_STATIC(SmsCodeTemplateEnum.RIDE_STATIC.getCode(), AccountSmsModelConstant.SMS_WHC, getRideStaticTemplate()),
    MACHINE_LOSE(SmsCodeTemplateEnum.MACHINE_LOSE.getCode(), AccountSmsModelConstant.SMS_DS, getMachineLostTemplate()),

    ;

    private final String code;
    private final Integer templateId;
    private final String params;

    public static ApiStoreSmsTemplateEnum getTemplate(final String code) {
        return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values());
    }

    private static String getAlarmTemplate() {
        JSONObject params = new JSONObject();
        params.put("userCode", "{userCode}");
        params.put("accountId", "{accountName}");
        params.put("alarm", "{alarmDesc}");
        return params.toJSONString();
    }

    private static String getOrderNoPayTemplate() {
        JSONObject params = new JSONObject();
        params.put("rideTime", "{rideTime}");
        params.put("linkUrl", "{linkUrl}");
        return params.toJSONString();
    }

    private static String getRideStaticTemplate() {
        JSONObject params = new JSONObject();
        params.put("mins", "{mins}");
        return params.toJSONString();
    }

    private static String getMachineLostTemplate() {
        JSONObject params = new JSONObject();
        params.put("accountId", "{accountName}");
        params.put("userCode", "{userCode}");
        params.put("point", "{address}");
        params.put("alarm", "{alarmDesc}");
        return params.toJSONString();
    }
}
